<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Berita_model extends CI_Model {

    public function getBerita($limit = 10, $offset = 0) {
        $query = $this->db->get_where('berita', array('page !=' => 'aboutus'), $limit, $offset);
        return $query->result_array();
    }
    
    public function getCountBerita() {
    	$query = $this->db->get_where('berita', array('page !=' => 'aboutus'));
        return $query->num_rows();
    }
    
	public function getAboutus() {
        $query = $this->db->get_where('berita', array('page' => 'aboutus'), 1);
        return $query->result_array();
    }

    public function getBeritaById($id) {
        $query = $this->db->get_where('berita', array('id' => $id), 1);
        $result = $query->result_array();
        return $result[0];
    }

    public function updateBeritaById($param) {
        $id = $param['id'];
        $data = array(
            'page' => $param['page'],
            'judul' => $param['judul'],
            'judul_url' => $param['judul_url'],
            'synopsis' => $param['synopsis'],
            'isi' => $param['isi']
        );
        $this->db->where('id', $id);
        return $this->db->update('berita', $data);
    }

    public function insertBerita($param) {
        $data = array(
            'page' => $param['page'],
            'judul' => $param['judul'],
            'judul_url' => $param['judul_url'],
            'synopsis' => $param['synopsis'],
            'isi' => $param['isi'],
            'created' => date('Y-m-d H:i:s')
        );

        return $this->db->insert('berita', $data);
    }

    public function deleteBeritaById($id) {
        return $this->db->delete('berita', array('id' => $id));
    }

}